#include "gpio.h"
#include "main.h"
#include "soft_i2c.h"
#include "soft_i2c_Init.h"

//define soft I2c PORT PIN
#define _I2c1_SDA_PORT ADS1115_MOTOR_ADC_SDA_GPIO_Port
#define _I2c1_SDA_PIN  ADS1115_MOTOR_ADC_SDA_Pin
#define _I2c1_SCL_PORT ADS1115_MOTOR_ADC_SCL_GPIO_Port
#define _I2c1_SCL_PIN  ADS1115_MOTOR_ADC_SCL_Pin


static void delay_us(uint32_t time)
{
  uint32_t delay_count = time * 180;
  while(delay_count--)
  {
  }
}

//define i2c1 function
void set_sda_i2c1(int32_t state)
{
  HAL_GPIO_WritePin(_I2c1_SDA_PORT, _I2c1_SDA_PIN, (GPIO_PinState)state);
}

void set_scl_i2c1(int32_t state)
{
  HAL_GPIO_WritePin(_I2c1_SCL_PORT, _I2c1_SCL_PIN, (GPIO_PinState)state);

}

int32_t get_sda_i2c1(void)
{
  return HAL_GPIO_ReadPin(_I2c1_SDA_PORT, _I2c1_SDA_PIN);
}


soft_i2c_driver ADS1115_I2c =
{
	.set_sda = set_sda_i2c1,
	.set_scl = set_scl_i2c1,
	.get_sda = get_sda_i2c1,
	.udelay = delay_us,
	.writeAddr = 0x92,
	.delay_us = 2,
	.waitTime = 1,
};

